<?php
/**
 * 用户查询功能模块
 * @author:linyue
 * @since:2102 4.18
 */
class UserProduct_Result{
    const TABLE_NAME_SEARCH = 'productinfo';
    const TABLE_NAME        = 'userproduct';
    
     protected $Pid;
      /**
       * 单例对象
     */
    public static $singletonObjects = array();
    
    
      /**
	 * 获取单例
	 * @param $uId 用户ID
	 * @return User_Info
	 * @throws AppException
     */
	public static function getInstance( $uId ){
		$className = __CLASS__;
		if( !isset( self::$singletonObjects[$uId][$className] ) ){
			self::$singletonObjects[$uId][$className] = new self( $uId );
		}

		return self::$singletonObjects[$uId][$className];
	}
    /**
     * 构造器
     * @param:pid
     */
       public function __construct($Pid){
          $this->Pid=$Pid;
       }
    /**
     * 防伪码查询结果
     * @param int $code 防伪码
     * @return 
     */
    
    public static  function select ($code) 
    {
        $where = array(
            'key' => $code,
        );
        $userInfo = Indexer::getInstance( 1);
       // print_r($userInfo);
       // $userInfo = Indexer::getInstance( $this->Pid )->getDb()->get( self::TABLE_NAME , array( 'uId' => $this->uId ) );
       /// Common::getMysql()->get( self::TABLE_NAME_SEARCH , $where );
       // $type = 0;
       // $where='PId=(select `PId` from productkey where `key`='.$code.')';
       // $userInfo = Common::getMysql()->get( self::TABLE_NAME_SEARCH ,$where);
         //print_r($userInfo);
         //return $userInfo;  
    }
    //判断用户所查询的产品记录是否存在
    public static function searchExist($uid,$pid)
    {
        
        $userProduct = Common::getMysql()->get( self::TABLE_NAME , array( 'UId' => $uid , 'PId' => $pid ) );
        return $userProduct;
    }
    //用户查询信息写入SQL
    public static function writeSql($uid,$pid,$count,$time) {
        $intoSql =  Common::getMysql()->add(self::TABLE_NAME, array( 'UId'=>$uid , 'PId'=>$pid , 'Count'=>$count , 'UpdateTime'=>$time));
       // return $intoSql;
    }
     //设置MC
    public function setMc() {

        $memcache = Common::getCache();
        $memcache->add('userProduct', '');
    }
    //用户查询写入MC
    public static function writeMc($uid , $pid , $date) {
        //$value = array($this->PId=>array($this->Count, $this->UpdateTime));
        $userProduct = Common::getCache()->get('userProduct');
        $userProduct[$uid] = array( $pid=>array( $uid , $date) );
        Common::getCache()->set('userProduct', $userProduct);
    }

   
}